package com.westvalley.ctrl;

import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.jfinal.ext.annotation.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.render.JsonRender;
import com.westvalley.common.kit.StringKit;

@ControllerBind(route="/mobile/plugin/WebApi")
public class WebApi extends Controller{
	/**
	 * 角色信息
	 */
	public void roleInfo(){
		JSONObject json = new JSONObject();
		try{
			JSONArray arr = new JSONArray();
			List<Record> list = Db.find("SELECT * FROM HRMROLES ORDER BY ID");
			for(Record r : list){
				JSONObject ob = new JSONObject();
				ob.put("roleId", StringKit.null2o(r.get("ID")));
				ob.put("roleName", StringKit.null2o(r.get("ROLESNAME")));
				ob.put("roleType", "OA角色");
				arr.add(ob);
			}
			json.put("code", 0);
			json.put("result", arr);
			json.put("msg", "成功返回"+list.size()+"条数据");
		}catch (Exception e) {
			json.put("code", -1);
			json.put("msg", e.getMessage());
		}
		render(new JsonRender(json.toJSONString()).forIE());
	}
}
